package Main;

import java.awt.CardLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

import simulationClasses.CPUMain;


public class SimulationPane extends JPanel implements ActionListener{
	private JCheckBox j1;
	private JCheckBox j2;
	private JCheckBox j3;
	private JCheckBox j4;
	private JCheckBox j5;
	private JCheckBox j6;
	private JCheckBox j7;
	private JCheckBox j8;
	private CPUMain cpu;
	private JPanel parent;
	private CardLayout cards;
	private JButton jBtn;
	private FileReader fr;
	public SimulationPane(JPanel parent, CardLayout cards, FileReader fr){
		this.fr =fr;
		this.setFocusable(true);
		this.setLayout(null);
		this.parent=parent;
		this.cards=cards;
		Font font= new Font(Font.SANS_SERIF, Font.PLAIN, 14);
		
		JLabel j= new JLabel("Choose 1 to Simulate");
		JPanel check= new JPanel(new GridLayout(4, 2));
		JCheckBox jc1 = new JCheckBox();
		
		j.setFont(font);
		j.setBounds(500, 60, j.getPreferredSize().width, 40);
		check.setBounds(300, 150, 750, 450);
		this.add(j);
		j1 = new JCheckBox("       CPU Scheduling");
		j2 = new JCheckBox("       Resource Scheduling");
		j3 = new JCheckBox("       Deadlock avoidance");
		j4 = new JCheckBox("       Detection and Recovery");
		j5 = new JCheckBox("       Process and Synchronization");
		j6 = new JCheckBox("       Virtual Memory Management");
		j7 = new JCheckBox("       Page Replacement");
		j8 = new JCheckBox("       Thrashing Prevention/Management");
		
		
		check.add(j1); 
		check.add(j2); 
		check.add(j3); 
		check.add(j4); 
		check.add(j5); 
		check.add(j6); 
		check.add(j7); 
		check.add(j8); 
		
		this.add(jBtn=new JButton("Proceed to Simulation"));
		jBtn.setBounds(200, 650, 750, 50);
		jBtn.addActionListener(this);
		this.add(jBtn);
		this.add(check);
		cpu=null;
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		// TODO Auto-generated method stub
		if(j1.isSelected()){
			if(cpu==null){
				cpu = new CPUMain(parent, cards, fr);
				parent.add(cpu, 4+"");
			}
			cards.show(parent, 4+"");
		}
		
	
	} 
}
